package com.learnyou.server.xingzuo.common.helper;

import cn.hutool.core.collection.CollectionUtil;
import org.dozer.Mapper;

import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public class MapperHelper {
    public static <I, O> O map(Mapper mapper, I original, Class<O> distClazz) {
        if (Objects.isNull(original)) {
            return null;
        } else {
            return mapper.map(original, distClazz);
        }
    }

    public static <I, O> List<O> map(Mapper mapper, List<I> original, Class<O> distClazz) {

        if (CollectionUtil.isNotEmpty(original)) {
            return original.stream().map(item -> map(mapper, item, distClazz)).collect(Collectors.toList());
        } else {
            return Collections.emptyList();
        }
    }
}
